/**
 * 
 */
package co.gov.medellin.sdep.sisdep.gestion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.gestion.exception.ConceptoInicialException;
import co.gov.medellin.sdep.sisdep.gestion.exception.ConceptoInicialRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.ConceptoInicialMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.ConceptoInicial;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IConceptoInicialDAOT;

/**
 * @author Usuario
 *
 */
public class ConceptoInicialServiceImpl extends BaseService implements IConceptoInicialService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IConceptoInicialDAOT conceptoInicialDAO;

	/**
	 * 
	 */
	public ConceptoInicialServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(ConceptoInicial conceptoInicial) throws ConceptoInicialException {
		try{
			conceptoInicial.setUsuarioCrea(getPrincipalUser());
			getConceptoInicialDAO().insert(conceptoInicial);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ConceptoInicialException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ConceptoInicialException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(ConceptoInicial conceptoInicial) throws ConceptoInicialException {
		try{
			conceptoInicial.setUsuarioModifica(getPrincipalUser());
			conceptoInicial.setFechaModifica(new Date());
			getConceptoInicialDAO().update(conceptoInicial);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ConceptoInicialRuntimeException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ConceptoInicialRuntimeException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(ConceptoInicial conceptoInicial) throws ConceptoInicialException {
		try {
			conceptoInicial.setUsuarioModifica(getPrincipalUser());
			conceptoInicial.setFechaModifica(new Date());
			getConceptoInicialDAO().delete(conceptoInicial);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new ConceptoInicialRuntimeException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, ConceptoInicial conceptoInicial) throws ConceptoInicialException {
		try{
			//return getConceptoInicialDAO().getAllConceptoInicialPaginated(start, max, criteria);
			return getConceptoInicialDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ConceptoInicialRuntimeException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List loadByRadicado(int start,int max, ConceptoInicial conceptoInicial) throws ConceptoInicialException {
		try{
			//return getConceptoInicialDAO().getAllConceptoInicialPaginated(start, max, criteria);
			return getConceptoInicialDAO().loadByRadicado(conceptoInicial);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ConceptoInicialRuntimeException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	public final List loadByIdSolicitud(int start,int max, ConceptoInicial conceptoInicial) throws ConceptoInicialException {
		try{
			//return getConceptoInicialDAO().getAllConceptoInicialPaginated(start, max, criteria);
			return getConceptoInicialDAO().loadByIdSolicitud(conceptoInicial);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ConceptoInicialRuntimeException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final ConceptoInicial get(long id) throws ConceptoInicialException {
		try{
			return getConceptoInicialDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new ConceptoInicialRuntimeException(new ConceptoInicialMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	public ConceptoInicial getConceptoInicialRelatedBy(long idSolicitud)
			throws ConceptoInicialException {
		try {
			ConceptoInicial criteria = new ConceptoInicial();
			criteria.setIdSolicitud(new Long(idSolicitud));
			return getConceptoInicialDAO().findByCriteria(criteria);
		} catch (Exception e) {
			Object[] infoError = { new Long(idSolicitud) };
			throw new ConceptoInicialRuntimeException(
					new ConceptoInicialMessageDescriptor(
							MessageDescriptorConstant.GET), infoError, e);
		}
	}
	
	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IConceptoInicialDAOT getConceptoInicialDAO() {
		return conceptoInicialDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setConceptoInicialDAO(IConceptoInicialDAOT conceptoInicialDAO) {
		this.conceptoInicialDAO = conceptoInicialDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
